<template>
  <div>
    <div style="height: 60px; background-color: #fff; display: flex; align-items: center; border-bottom: 1px solid #ddd">
      <div style="flex: 1">
        <div style="padding-left: 20px; display: flex; align-items: center">
          <img src="@/assets/imgs/logo.png" alt="" style="width: 40px">
          <div style="font-weight: bold; font-size: 24px; margin-left: 5px">百业兴点餐后台</div>
        </div>
      </div>
      <div style="width: fit-content; padding-right: 10px; display: flex; align-items: center;">
        <img src="@/assets/imgs/head.jpg" alt="" style="width: 40px; height: 40px">
        <span style="margin-left: 5px">{{user.username}}</span>
      </div>
    </div>

    <div style="display: flex">
      <div style="width: 200px; border-right: 1px solid #ddd; min-height: calc(100vh - 60px)">
        <el-menu
            router
            style="border: none"
            :default-active="$route.path"
            :default-openeds="['/home', '2']"
        >
          <el-menu-item index="/home">
            <el-icon><Shop /></el-icon>
            <span>系统首页</span>
          </el-menu-item>
          <el-sub-menu index="2">
            <template #title>
              <el-icon><ForkSpoon /></el-icon>
              <span>餐品信息</span>
            </template>
            <el-menu-item index="/productCategory">
              <el-icon><Document /></el-icon>
              <span>餐品类别</span>
            </el-menu-item>
            <el-menu-item index="/productInfo">
              <el-icon><Bowl /></el-icon>
              <span>餐品管理</span>
            </el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="3">
            <template #title>
              <el-icon><CoffeeCup /></el-icon>
              <span>订单管理</span>
            </template>
            <el-menu-item index="/orderMaster">
              <el-icon><DocumentChecked /></el-icon>
              <span>订单信息</span>
            </el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="4">
            <template #title>
              <el-icon><User /></el-icon>
              <span>安全管理</span>
            </template>
            <el-menu-item index="/loginLog">
              <el-icon><Menu /></el-icon>
              <span>登录日志</span>
            </el-menu-item>
            <el-menu-item index="/systemLog">
              <el-icon><Menu /></el-icon>
              <span>用户日志</span>
            </el-menu-item>
            <el-menu-item index="/passWord">
              <el-icon><Briefcase /></el-icon>
              <span>密码修改</span>
            </el-menu-item>
          </el-sub-menu>
          <el-menu-item @click="logout">
            <el-icon><SwitchButton /></el-icon>
            <span>退出系统</span>
          </el-menu-item>
        </el-menu>
      </div>

      <div style="flex: 1; width: 0; background-color: #f8f8ff; padding: 10px">
        <router-view />
      </div>
    </div>

  </div>
</template>

<script setup>

import {useRoute} from 'vue-router'
import {ElMessageBox} from "element-plus";
import router from "@/router";

const $route = useRoute()
console.log($route.path)

const user = JSON.parse(localStorage.getItem('user') || '{}')

const logout = () => {
  ElMessageBox.confirm('确定退出系统吗?', '确认', { type: 'warning' }).then(res => {
    //清楚本地的localStorage
    localStorage.removeItem('user');
    localStorage.removeItem('token');
    router.push('/login')// 登录页面
  }).catch(err => {
    console.log(err);
  })
}

</script>

<style scoped>
  .el-menu-item.is-active {
    background-color: #dcede9 !important;
  }
  .el-menu-item:hover {
    color: #11A983;
  }
  :deep(th)  {
    color: #333;
  }
</style>